import { lazy } from 'react'

const Tooltip = lazy(()=>import('@antd/tooltip'))

const Index = {
	// 表格配置
	table:{
		time: { width:120, align:'center' },
		sex: { width:50, align:'center' },
		age: { width:50, align:'center' },
		phone: { width:90, align:'center' },
		email: { width:100 },
		name: { width:80, align:'center' },
		date: { width:80, align:'center' },
		money: { width:90, align:'center' },	// 金额
		controls : { width:120, align:'center', fixed:'right' },
		bool: { width:50, align:'center', render: text => ( typeof text === 'boolean' ? text : Boolean(+text) ) ? '是' : '否' },
		state: (data, fields) => ({ render: text => window.$fn.getState(data, text, fields) }),
		sexState: (fields='sex') => ({ width:50, align:'center', render: text => text ? window.$fn.getState(Index.sexData, text, fields) : '未知' }),
		tags: () => ({ width:200, ellipsis:true, render: text => {
			if( text ) {
				let rs = text.join('、')
				return rs.length > 2 ? <Tooltip title={rs}>{rs}</Tooltip> : rs
			}
		} }),
		tip: { ellipsis:true, render: t => t ? <Tooltip title={t}>{t}</Tooltip> : null },
	},
	getState(data, value, fields){
		const { nameStr = 'label', idStr = 'value' } = fields || {}
		if( Array.isArray( data ) ){
			const arr = data.filter( item => String(item[idStr]) === String(value) )
			return arr.length === 1 ? arr[0][nameStr] : ''
		}else{
			return ''
		}
	},
	sexData: [
		{ label:'男', value: 1 },
		{ label:'女', value: 2 },
		{ label:'未知', value: 0 }
	],
	boolData : [{ label:'是', value: 1 }, { label:'否', value: 0 }]
}

export default Index